package JDBC;

import java.sql.*;

import static java.lang.Class.forName;

public class ConnDatabase {
    public static Connection getconn(String url,String username,String password) throws ClassNotFoundException, SQLException {
        Connection conn=null;
        Class.forName("com.mysql.cj.jdbc.Driver");
        conn= DriverManager.getConnection(url,username,password);
        return conn;
    }

    //关闭数据库
    public static void close(Connection conn, PreparedStatement ps,ResultSet rs) throws SQLException {
        if (rs!=null){
            rs.close();
        }
        if (ps!=null){
            ps.close();
        }
        if (conn!=null){
            conn.close();
        }
    }

}
